﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Enter.Admin.Utils
{
    public class RegexTools
    {
        // 提取字符串中的日期;
        public static List<DateTime> ExtractDate(string input)
        {
            List<DateTime> dts = new List<DateTime>();
            Regex reg = new Regex(@"[\d]{4}[-|\/][\d]{1,2}[-|\/][\d]{1,2}");
            MatchCollection mc = reg.Matches(input);
            foreach (Match m in mc)
            {
                if (DateTime.TryParse(m.Value, out DateTime mDate)) 
                {
                    if(mDate!=DateTime.MinValue)dts.Add(mDate);
                }
            }
            return dts;
        }
    }
}
